package com.wqi.chapter7;

public class Sequence {

	private Object[] o;
	private int next = 0;
	public Sequence(int size){
		o = new Object[size];
	}
	public void add(Object x){
		if(next < o.length){
			o[next] = x;
			next ++;
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Sequence s = new Sequence(10);
		for(int i=0;i<10;i++){
			s.add(Integer.toString(i));
		}
		Selector s1 = s.getSelector();
		while(!s1.end()){
			System.out.println((String)s1.current());
			s1.next();
		}
	}
	
	public Selector getSelector(){
		return new SSelector();
	}
	
	private class SSelector implements Selector{
		int i=0;
		@Override
		public Object current() {
			return o[i];
		}

		@Override
		public boolean end() {
			return i == o.length;
		}

		@Override
		public void next() {
			if(i <o.length) i++;
			
		}
		
	}
}

interface Selector{
	boolean end();
	Object current();
	void next();
}
